#include "Shortcut.hpp"

Shortcut::Shortcut(QString n, bool g) : name(n), global(g) {
    if(!global) {
        applicationShortcut=new QAction(0);
        applicationShortcut->setShortcutContext ( Qt::ApplicationShortcut );
        globalShortcut=0;
        connect(applicationShortcut, SIGNAL(activated()), this, SLOT());
    } else {
        globalShortcut=new QxtGlobalShortcut(0);
        applicationShortcut=0;
        connect(globalShortcut, SIGNAL(activated()), this, SLOT());
    }
}
Shortcut::~Shortcut() {
    if(global) delete globalShortcut;
    else delete applicationShortcut;
}

bool Shortcut::isGlobal() {return global;}
QString Shortcut::getName() {return name;}
bool Shortcut::set(const QKeySequence& s) {
    if(global) return globalShortcut->setShortcut(s);
    applicationShortcut->setShortcut(s);
    return true;
}
QKeySequence Shortcut::get() const {
    if(global) return globalShortcut->shortcut();
    return applicationShortcut->shortcut();
}

QObject* Shortcut::getObject() const {
    if(global) return globalShortcut;
    else return applicationShortcut;
}

QString Shortcut::getStringSequence() { return get().toString(QKeySequence::PortableText); }
